﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;
using System.Collections.Generic;//Please add references
namespace EnterpriseFund.DAL
{
    /// <summary>
    /// 数据访问类:UpLevelAllowance
    /// </summary>
    public partial class UpLevelAllowance
    {
        public UpLevelAllowance()
        { }
        #region  BasicMethod

        /// <summary>
        /// 增加文件
        /// </summary>
        /// <param name="enList"></param>
        /// <param name="model"></param>
        public void Add(List<Model.UpLevelAllowanceEntry> enList, Model.UpLevelAllowance model)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();

            var getBillIdSql = "exec sp_getbillno 'fund.t_UpLevelAllowance','FUpLevelAllowanceID','','','',@returnBId output ";
            var getBillIdPar = new SqlParameter[]{ 
                new SqlParameter("@returnBId", SqlDbType.NVarChar, 50)
            };

            getBillIdPar[0].Direction = ParameterDirection.Output;

            cmds.CommandText = getBillIdSql.ToString();
            cmds.Parameters = getBillIdPar;
            cmdList.Add(cmds);

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("insert into fund.t_UpLevelAllowance(");
            strSql.Append("FUpLevelAllowanceID,FFileName,FIsReturn,FFileNo,FFileTransDate,FNote,FStatus,FFinancePropNo,FIsAudit,FYear,FUpLevelAllowanceClsNo,FEntityNo,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP)");
            strSql.Append(" values (");
            strSql.Append("@returnBId,@FFileName,@FIsReturn,@FFileNo,@FFileTransDate,@FNote,@FStatus,@FFinancePropNo,@FIsAudit,@FYear,@FUpLevelAllowanceClsNo,@FEntityNo,@FInsEmpNo,@FInsDeptNo,@FInsDate,@FInsIP)");
            SqlParameter[] parameters = {
					new SqlParameter("@returnBId", SqlDbType.NVarChar,50),
					new SqlParameter("@FFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FIsReturn", SqlDbType.NVarChar,1),
					new SqlParameter("@FFileNo", SqlDbType.NVarChar,50),
					new SqlParameter("@FFileTransDate", SqlDbType.DateTime),
					new SqlParameter("@FNote", SqlDbType.NVarChar,255),
					new SqlParameter("@FStatus", SqlDbType.NVarChar,1),
					new SqlParameter("@FFinancePropNo", SqlDbType.NVarChar,6),
					new SqlParameter("@FIsAudit", SqlDbType.NVarChar,1),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FUpLevelAllowanceClsNo", SqlDbType.NVarChar,6),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FInsEmpNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FInsDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FInsDate", SqlDbType.DateTime),
					new SqlParameter("@FInsIP", SqlDbType.NVarChar,15)};
            parameters[0].Direction = ParameterDirection.InputOutput;
            parameters[1].Value = model.FFileName;
            parameters[2].Value = model.FIsReturn;
            parameters[3].Value = model.FFileNo;
            parameters[4].Value = model.FFileTransDate;
            parameters[5].Value = model.FNote;
            parameters[6].Value = model.FStatus;
            parameters[7].Value = model.FFinancePropNo;
            parameters[8].Value = model.FIsAudit;
            parameters[9].Value = model.FYear;
            parameters[10].Value = model.FUpLevelAllowanceClsNo;
            parameters[11].Value = model.FEntityNo;
            parameters[12].Value = model.FInsEmpNo;
            parameters[13].Value = model.FInsDeptNo;
            parameters[14].Value = model.FInsDate;
            parameters[15].Value = model.FInsIP;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            foreach (Model.UpLevelAllowanceEntry enModel in enList)
            {
                cmds = new CommandInfo();
                var getBillIdSql2 = "exec sp_getbillno 'fund.t_UpLevelAllowanceEntry','FUpLevelAllowanceEntryID','','','',@returnBId2 output ";
                var getBillIdPar2 = new SqlParameter[]{ 
                new SqlParameter("@returnBId2", SqlDbType.NVarChar, 50)
                };

                getBillIdPar2[0].Direction = ParameterDirection.Output;

                cmds.CommandText = getBillIdSql2.ToString();
                cmds.Parameters = getBillIdPar2;
                cmdList.Add(cmds);

                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("insert into fund.t_UpLevelAllowanceEntry(");
                strSql.Append("FUpLevelAllowanceEntryID,NSRDZDAH,FUpLevelAmount,FLocalAmount,FUpLevelAllowanceID,FNote)");
                strSql.Append(" values (");
                strSql.Append("@returnBId2,@NSRDZDAH,@FUpLevelAmount,@FLocalAmount,@returnBId,@FNote)");
                SqlParameter[] parameters2 = {
					new SqlParameter("@returnBId2", SqlDbType.NVarChar,255),
					new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,13),
					new SqlParameter("@FUpLevelAmount", SqlDbType.Decimal,9),
					new SqlParameter("@FLocalAmount", SqlDbType.Decimal,9),
					new SqlParameter("@returnBId", SqlDbType.NVarChar,50),
					new SqlParameter("@FNote", SqlDbType.NVarChar,255)};
                parameters2[0].Direction = ParameterDirection.InputOutput;
                parameters2[1].Value = enModel.NSRDZDAH;
                parameters2[2].Value = enModel.FUpLevelAmount;
                parameters2[3].Value = enModel.FLocalAmount;
                parameters2[4].Direction = ParameterDirection.InputOutput;
                parameters2[5].Value = enModel.FNote;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters2;
                cmdList.Add(cmds);
            }


            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithCommonList(cmdList);
            }
        }


        /// <summary>
        /// 增加文件
        /// </summary>
        /// <param name="enList"></param>
        /// <param name="model"></param>
        public void Update(List<Model.UpLevelAllowanceEntry> enList, Model.UpLevelAllowance model)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("update fund.t_UpLevelAllowance set ");
            strSql.Append("FFileName=@FFileName,");
            strSql.Append("FIsReturn=@FIsReturn,");
            strSql.Append("FFileNo=@FFileNo,");
            strSql.Append("FFileTransDate=@FFileTransDate,");
            strSql.Append("FNote=@FNote,");
            strSql.Append("FStatus=@FStatus,");
            strSql.Append("FUpdEmplNo=@FUpdEmplNo,");
            strSql.Append("FUpdDeptNo=@FUpdDeptNo,");
            strSql.Append("FUpdDate=@FUpdDate,");
            strSql.Append("FUpdIP=@FUpdIP,");
            strSql.Append("FUpLevelAllowanceClsNo=@FUpLevelAllowanceClsNo,");
            strSql.Append("FIsAudit=@FIsAudit");
            strSql.Append(" where FUpLevelAllowanceID=@FUpLevelAllowanceID ");
            SqlParameter[] parameters = {
					new SqlParameter("@FFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FIsReturn", SqlDbType.NVarChar,1),
					new SqlParameter("@FFileNo", SqlDbType.NVarChar,50),
					new SqlParameter("@FFileTransDate", SqlDbType.DateTime),
					new SqlParameter("@FNote", SqlDbType.NVarChar,255),
					new SqlParameter("@FStatus", SqlDbType.NVarChar,1),
					new SqlParameter("@FUpdEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FUpdDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FUpdDate", SqlDbType.DateTime),
					new SqlParameter("@FUpdIP", SqlDbType.VarChar,15),
					new SqlParameter("@FUpLevelAllowanceID", SqlDbType.NVarChar,50),
					new SqlParameter("@FFinancePropNo", SqlDbType.NVarChar,6),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FUpLevelAllowanceClsNo", SqlDbType.NVarChar,6),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
                   
                                        		new SqlParameter("@FIsAudit", SqlDbType.NVarChar,1)};
            parameters[0].Value = model.FFileName;
            parameters[1].Value = model.FIsReturn;
            parameters[2].Value = model.FFileNo;
            parameters[3].Value = model.FFileTransDate;
            parameters[4].Value = model.FNote;
            parameters[5].Value = model.FStatus;
            parameters[6].Value = model.FUpdEmplNo;
            parameters[7].Value = model.FUpdDeptNo;
            parameters[8].Value = model.FUpdDate;
            parameters[9].Value = model.FUpdIP;
            parameters[10].Value = model.FUpLevelAllowanceID;
            parameters[11].Value = model.FFinancePropNo;
            parameters[12].Value = model.FYear;
            parameters[13].Value = model.FUpLevelAllowanceClsNo;
            parameters[14].Value = model.FEntityNo;
       
            parameters[15].Value = model.FIsAudit;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("delete from fund.t_UpLevelAllowanceEntry ");
            strSql.Append(" where FUpLevelAllowanceID=@FUpLevelAllowanceID ");
            SqlParameter[] parameters3 = {
					new SqlParameter("@FUpLevelAllowanceID", SqlDbType.NVarChar,50)			};
            parameters3[0].Value = model.FUpLevelAllowanceID;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters3;
            cmdList.Add(cmds);

            foreach (Model.UpLevelAllowanceEntry enModel in enList)
            {
                cmds = new CommandInfo();
                var getBillIdSql2 = "exec sp_getbillno 'fund.t_UpLevelAllowanceEntry','FUpLevelAllowanceEntryID','','','',@returnBId2 output ";
                var getBillIdPar2 = new SqlParameter[]{ 
                new SqlParameter("@returnBId2", SqlDbType.NVarChar, 50)
                };

                getBillIdPar2[0].Direction = ParameterDirection.Output;

                cmds.CommandText = getBillIdSql2.ToString();
                cmds.Parameters = getBillIdPar2;
                cmdList.Add(cmds);

                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("insert into fund.t_UpLevelAllowanceEntry(");
                strSql.Append("FUpLevelAllowanceEntryID,NSRDZDAH,FUpLevelAmount,FLocalAmount,FUpLevelAllowanceID,FNote)");
                strSql.Append(" values (");
                strSql.Append("@returnBId2,@NSRDZDAH,@FUpLevelAmount,@FLocalAmount,@FUpLevelAllowanceID,@FNote)");
                SqlParameter[] parameters2 = {
					new SqlParameter("@returnBId2", SqlDbType.NVarChar,255),
					new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,13),
					new SqlParameter("@FUpLevelAmount", SqlDbType.Decimal,9),
					new SqlParameter("@FLocalAmount", SqlDbType.Decimal,9),
					new SqlParameter("@FUpLevelAllowanceID", SqlDbType.NVarChar,50),
					new SqlParameter("@FNote", SqlDbType.NVarChar,255)};
                parameters2[0].Direction = ParameterDirection.InputOutput;
                parameters2[1].Value = enModel.NSRDZDAH;
                parameters2[2].Value = enModel.FUpLevelAmount;
                parameters2[3].Value = enModel.FLocalAmount;
                parameters2[4].Value = model.FUpLevelAllowanceID;
                parameters2[5].Value = enModel.FNote;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters2;
                cmdList.Add(cmds);
            }


            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithCommonList(cmdList);
            }
        }
        public void Update2(List<Model.UpLevelAllowanceEntry> enList, Model.UpLevelAllowance model)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("update fund.t_UpLevelAllowance set ");
            strSql.Append("FFileName=@FFileName,");
            strSql.Append("FIsReturn=@FIsReturn,");
            strSql.Append("FFileNo=@FFileNo,");
            strSql.Append("FFileTransDate=@FFileTransDate,");
            strSql.Append("FNote=@FNote,");
            strSql.Append("FStatus=@FStatus,");
            strSql.Append("FUpdEmplNo=@FUpdEmplNo,");
            strSql.Append("FUpdDeptNo=@FUpdDeptNo,");
            strSql.Append("FUpdDate=@FUpdDate,");
            strSql.Append("FUpdIP=@FUpdIP");
            strSql.Append(" where FUpLevelAllowanceID=@FUpLevelAllowanceID ");
            SqlParameter[] parameters = {
					new SqlParameter("@FFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FIsReturn", SqlDbType.NVarChar,1),
					new SqlParameter("@FFileNo", SqlDbType.NVarChar,50),
					new SqlParameter("@FFileTransDate", SqlDbType.DateTime),
					new SqlParameter("@FNote", SqlDbType.NVarChar,255),
					new SqlParameter("@FStatus", SqlDbType.NVarChar,1),
					new SqlParameter("@FUpdEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FUpdDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FUpdDate", SqlDbType.DateTime),
					new SqlParameter("@FUpdIP", SqlDbType.VarChar,15),
					new SqlParameter("@FUpLevelAllowanceID", SqlDbType.NVarChar,50),
					new SqlParameter("@FFinancePropNo", SqlDbType.NVarChar,6),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FUpLevelAllowanceClsNo", SqlDbType.NVarChar,6),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
            parameters[0].Value = model.FFileName;
            parameters[1].Value = model.FIsReturn;
            parameters[2].Value = model.FFileNo;
            parameters[3].Value = model.FFileTransDate;
            parameters[4].Value = model.FNote;
            parameters[5].Value = model.FStatus;
            parameters[6].Value = model.FUpdEmplNo;
            parameters[7].Value = model.FUpdDeptNo;
            parameters[8].Value = model.FUpdDate;
            parameters[9].Value = model.FUpdIP;
            parameters[10].Value = model.FUpLevelAllowanceID;
            parameters[11].Value = model.FFinancePropNo;
            parameters[12].Value = model.FYear;
            parameters[13].Value = model.FUpLevelAllowanceClsNo;
            parameters[14].Value = model.FEntityNo;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

           

            foreach (Model.UpLevelAllowanceEntry enModel in enList)
            {
                cmds = new CommandInfo();
                var getBillIdSql2 = "exec sp_getbillno 'fund.t_UpLevelAllowanceEntry','FUpLevelAllowanceEntryID','','','',@returnBId2 output ";
                var getBillIdPar2 = new SqlParameter[]{ 
                new SqlParameter("@returnBId2", SqlDbType.NVarChar, 50)
                };

                getBillIdPar2[0].Direction = ParameterDirection.Output;

                cmds.CommandText = getBillIdSql2.ToString();
                cmds.Parameters = getBillIdPar2;
                cmdList.Add(cmds);

                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("insert into fund.t_UpLevelAllowanceEntry(");
                strSql.Append("FUpLevelAllowanceEntryID,NSRDZDAH,FUpLevelAmount,FLocalAmount,FUpLevelAllowanceID,FNote)");
                strSql.Append(" values (");
                strSql.Append("@returnBId2,@NSRDZDAH,@FUpLevelAmount,@FLocalAmount,@FUpLevelAllowanceID,@FNote)");
                SqlParameter[] parameters2 = {
					new SqlParameter("@returnBId2", SqlDbType.NVarChar,255),
					new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,13),
					new SqlParameter("@FUpLevelAmount", SqlDbType.Decimal,9),
					new SqlParameter("@FLocalAmount", SqlDbType.Decimal,9),
					new SqlParameter("@FUpLevelAllowanceID", SqlDbType.NVarChar,50),
					new SqlParameter("@FNote", SqlDbType.NVarChar,255)};
                parameters2[0].Direction = ParameterDirection.InputOutput;
                parameters2[1].Value = enModel.NSRDZDAH;
                parameters2[2].Value = enModel.FUpLevelAmount;
                parameters2[3].Value = enModel.FLocalAmount;
                parameters2[4].Value = model.FUpLevelAllowanceID;
                parameters2[5].Value = enModel.FNote;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters2;
                cmdList.Add(cmds);
            }


            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithCommonList(cmdList);
            }
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string FUpLevelAllowanceID)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();
            strSql.Append("delete from fund.t_UpLevelAllowanceEntry ");
            strSql.Append(" where FUpLevelAllowanceID=@FUpLevelAllowanceID ");
            SqlParameter[] parameters3 = {
					new SqlParameter("@FUpLevelAllowanceID", SqlDbType.NVarChar,50)			};
            parameters3[0].Value = FUpLevelAllowanceID;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters3;
            cmdList.Add(cmds);

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("delete from fund.t_UpLevelAllowance ");
            strSql.Append(" where FUpLevelAllowanceID=@FUpLevelAllowanceID ");
            SqlParameter[] parameters = {
					new SqlParameter("@FUpLevelAllowanceID", SqlDbType.NVarChar,50)			};
            parameters[0].Value = FUpLevelAllowanceID;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithCommonList(cmdList);
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool UpdateStatus(EnterpriseFund.Model.UpLevelAllowance model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update fund.t_UpLevelAllowance set ");
            strSql.Append("FIsReturn=@FIsReturn,");
            strSql.Append("FStatus=@FStatus");
            strSql.Append(" where FUpLevelAllowanceID=@FUpLevelAllowanceID ");
            SqlParameter[] parameters = {
					new SqlParameter("@FIsReturn", SqlDbType.NVarChar,1),
					new SqlParameter("@FStatus", SqlDbType.NVarChar,1),
					new SqlParameter("@FUpLevelAllowanceID", SqlDbType.NVarChar,50)};
            parameters[0].Value = model.FIsReturn;
            parameters[1].Value = model.FStatus;
            parameters[2].Value = model.FUpLevelAllowanceID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string FUpLevelAllowanceIDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from fund.t_UpLevelAllowance ");
            strSql.Append(" where FUpLevelAllowanceID in (" + FUpLevelAllowanceIDlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.UpLevelAllowance GetModel(string FUpLevelAllowanceID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FUpLevelAllowanceID,FFileName,FIsReturn,FFileNo,FFileTransDate,FNote,FStatus,FFinancePropNo,FIsAudit,FYear,FUpLevelAllowanceClsNo,FEntityNo,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FUpdEmplNo,FUpdDeptNo,FUpdDate,FUpdIP from fund.t_UpLevelAllowance ");
            strSql.Append(" where FUpLevelAllowanceID=@FUpLevelAllowanceID ");
            SqlParameter[] parameters = {
					new SqlParameter("@FUpLevelAllowanceID", SqlDbType.NVarChar,50)			};
            parameters[0].Value = FUpLevelAllowanceID;

            EnterpriseFund.Model.UpLevelAllowance model = new EnterpriseFund.Model.UpLevelAllowance();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.UpLevelAllowance DataRowToModel(DataRow row)
        {
            EnterpriseFund.Model.UpLevelAllowance model = new EnterpriseFund.Model.UpLevelAllowance();
            if (row != null)
            {
                if (row["FUpLevelAllowanceID"] != null)
                {
                    model.FUpLevelAllowanceID = row["FUpLevelAllowanceID"].ToString();
                }
                if (row["FFileName"] != null)
                {
                    model.FFileName = row["FFileName"].ToString();
                }
                if (row["FIsReturn"] != null)
                {
                    model.FIsReturn = row["FIsReturn"].ToString();
                }
                if (row["FFileNo"] != null)
                {
                    model.FFileNo = row["FFileNo"].ToString();
                }
                if (row["FFileTransDate"] != null && row["FFileTransDate"].ToString() != "")
                {
                    model.FFileTransDate = DateTime.Parse(row["FFileTransDate"].ToString());
                }
                if (row["FNote"] != null)
                {
                    model.FNote = row["FNote"].ToString();
                }
                if (row["FStatus"] != null)
                {
                    model.FStatus = row["FStatus"].ToString();
                }
                if (row["FFinancePropNo"] != null)
                {
                    model.FFinancePropNo = row["FFinancePropNo"].ToString();
                }
                if (row["FIsAudit"] != null)
                {
                    model.FIsAudit = row["FIsAudit"].ToString();
                }
                if (row["FYear"] != null && row["FYear"].ToString() != "")
                {
                    model.FYear = decimal.Parse(row["FYear"].ToString());
                }
                if (row["FUpLevelAllowanceClsNo"] != null)
                {
                    model.FUpLevelAllowanceClsNo = row["FUpLevelAllowanceClsNo"].ToString();
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FInsEmpNo"] != null)
                {
                    model.FInsEmpNo = row["FInsEmpNo"].ToString();
                }
                if (row["FInsDeptNo"] != null)
                {
                    model.FInsDeptNo = row["FInsDeptNo"].ToString();
                }
                if (row["FInsDate"] != null && row["FInsDate"].ToString() != "")
                {
                    model.FInsDate = DateTime.Parse(row["FInsDate"].ToString());
                }
                if (row["FInsIP"] != null)
                {
                    model.FInsIP = row["FInsIP"].ToString();
                }
                if (row["FUpdEmplNo"] != null)
                {
                    model.FUpdEmplNo = row["FUpdEmplNo"].ToString();
                }
                if (row["FUpdDeptNo"] != null)
                {
                    model.FUpdDeptNo = row["FUpdDeptNo"].ToString();
                }
                if (row["FUpdDate"] != null && row["FUpdDate"].ToString() != "")
                {
                    model.FUpdDate = DateTime.Parse(row["FUpdDate"].ToString());
                }
                if (row["FUpdIP"] != null)
                {
                    model.FUpdIP = row["FUpdIP"].ToString();
                }
                if (row.Table.Columns.Contains("sumFAmount"))
                {
                    if (row["sumFAmount"] != null)
                    {
                        model.sumFAmount = row["sumFAmount"].ToString();
                    }
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FUpLevelAllowanceID,FFileName,FIsReturn,FFileNo,FFileTransDate,FNote,FStatus,FFinancePropNo,FIsAudit,FYear,FUpLevelAllowanceClsNo,FEntityNo,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FUpdEmplNo,FUpdDeptNo,FUpdDate,FUpdIP ");
            strSql.Append(" FROM fund.t_UpLevelAllowance ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" FUpLevelAllowanceID,FFileName,FIsReturn,FFileNo,FFileTransDate,FNote,FStatus,FFinancePropNo,FIsAudit,FYear,FUpLevelAllowanceClsNo,FEntityNo,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FUpdEmplNo,FUpdDeptNo,FUpdDate,FUpdIP ");
            strSql.Append(" FROM fund.t_UpLevelAllowance ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }
       // fund.v_UpLevelAllowance

            public int GetRecordCount2(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM fund.v_UpLevelAllowance ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM fund.t_UpLevelAllowance ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.FUpLevelAllowanceID desc");
            }
            strSql.Append(")AS Row, T.*  from fund.t_UpLevelAllowance T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "t_UpLevelAllowance";
            parameters[1].Value = "FUpLevelAllowanceID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

